package mo.leetcode_top;

public class L169 {

    public int majorityElement(int[] nums) {
        int count = 0;
        int candidate = 0;

        for (int num : nums) {
            if (count == 0) {
                candidate = num;
            }
            count += num == candidate ? 1 : -1;
            if (count > nums.length/2) {
                break;
            }
        }

        return candidate;
    }

}
